#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e5 + 10, INF = 0x3f3f3f3f;

ll n, m;
ll a[N * 2];
ll cnt[1000010];

void solve()
{
    cin >> n >> m;
    for (ll i = 1;i <= n;i++) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    for (ll i = 1;i < 2 * n;i++)
        a[i] = (a[i - 1] + a[i]) % m;

    ll ans = 0, l = 1, r = 1;
    while (r < 2 * n) {
        if (r - l + 1 > n) { cnt[a[l]]--; l++; }
        ans += cnt[a[r]];
        if (r <= n) cnt[a[r]]++;
        r++;
    }
    cout << ans;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}

// 1 2 3 4  1  2  3  4
// 2 1 4 3  2  1  4  3
// 2 3 7 10 12 13 17 20
// 2 0 1 1  0  1  2  2